2020-2021 Sunseeker Telemetry and Lighting System
usci_b_i2c_ex4_slaveTxMultiple.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #include "driverlib.h"
33 
34 //*****************************************************************************
51 //
52 //*****************************************************************************
53 //*****************************************************************************
54 //
55 //Set the address for slave module. This is a 7-bit address sent in the
56 //following format:
57 //[A6:A5:A4:A3:A2:A1:A0:RS]
58 //
59 //A zero in the "RS" position of the first byte means that the master
60 //transmits (sends) data to the selected slave, and a one in this position
61 //means that the master receives data from the slave.
62 //
63 //*****************************************************************************
64 #define SLAVE_ADDRESS 0x48
65 //*****************************************************************************
66 //
67 //Specify SMCLK frequency
68 //
69 //*****************************************************************************
70 #define TXLENGTH 0x05
71 
72 unsigned char transmitData[] = { 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
73  0xB0, 0xB1, 0xB2, 0xB3, 0xB4};
74 unsigned char *transmitDataPointer;
75 unsigned char transmitLength = TXLENGTH;
76 
77 void main ()
78 {
79  //Stop WDT
80  WDT_A_hold(WDT_A_BASE);
81 
82  //Assign I2C pins to USCI_B0
83  GPIO_setAsPeripheralModuleFunctionInputPin(
84  GPIO_PORT_P3,
85  GPIO_PIN1 + GPIO_PIN2
86  );
87 
88  //Initialize I2C as a slave device
89  USCI_B_I2C_initSlave(USCI_B0_BASE,
91  );
92 
93  //Set in transmit mode
94  USCI_B_I2C_setMode(USCI_B0_BASE,
95  USCI_B_I2C_TRANSMIT_MODE
96  );
97 
98  //Enable I2C Module to start operations
99  USCI_B_I2C_enable(USCI_B0_BASE);
100 
101  //Enable master trasmit interrupt
102  USCI_B_I2C_enableInterrupt(USCI_B0_BASE,
103  USCI_B_I2C_TRANSMIT_INTERRUPT + USCI_B_I2C_STOP_INTERRUPT
104  );
105 
106 
107  while (1)
108  {
111  //Enter low power mode 0 with interrupts enabled.
112  __bis_SR_register(LPM0_bits + GIE);
113 
114  __no_operation();
115  }
116 }
117 
118 //******************************************************************************
119 //
120 //This is the USCI_B0 interrupt vector service routine.
121 //
122 //******************************************************************************
123 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
124 #pragma vector=USCI_B0_VECTOR
125 __interrupt
126 #elif defined(__GNUC__)
127 __attribute__((interrupt(USCI_B0_VECTOR)))
128 #endif
129 void USCI_B0_ISR (void)
130 {
131  switch (__even_in_range(UCB0IV,12)){
132  case USCI_I2C_UCSTPIFG:
133  //Exit LPM0 if data was transmitted
134  __bic_SR_register_on_exit(LPM0_bits);
135  break;
136  case USCI_I2C_UCTXIFG:
137  //Transmit data
138  if (transmitLength > 0x00){
139  USCI_B_I2C_slavePutData(USCI_B0_BASE,
141  );
142  transmitLength--;
143  }
144 
145  break;
146  default:
147  break;
148  }
149 }
150 
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
unsigned char transmitData[]
unsigned char transmitLength
unsigned char * transmitDataPointer
void USCI_B0_ISR(void)
#define SLAVE_ADDRESS